home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c,comp.std.c
- Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
- Date: 02 Feb 1996 18:04:43 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb2110443@qcd.lanl.gov>
- References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM>
- <TANMOY.96Jan29090518@qcd.lanl.gov> <DM3wEy.FHH@mv.mv.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: ENGR@GSSI.MV.COM's message of Thu, 1 Feb 1996 16:56:57 GMT
-
- In article <DM3wEy.FHH@mv.mv.com> ENGR@GSSI.MV.COM (Michael Furman)
- writes:
- <snip>
- Not exactly. My question was not about diagnostics, but about usage
- of constructions that are not defined in standard.
- There are two kinds of undefined behavior:
- 1. When operation does not have any meaning. Example: assigning a value
- to dereferenced incorrect pointer. In such cases sometimes it is very
- hard or impossible (at least on some platforms) to check it even at
- execution time and it is really possible that hard disk will be
- reformatted as a result of such operations.
- 2. When operation has meaning but can not be portable defined for all
- platforms. Example: all number conversions that depends on internal
- representation or some CPU specific (like rounding). But I have more
- clear example: "asm" keyword. I found it is defined in C++ draft and
- I believe it is defined in C standard.
- Was it inserted just to give programmers some way to implement undefined
- behavior (with some chance to have disk reformatted)? I do not think so.
-
- First, asm is not a C keyword.
-
- Next, undefined behaviour doesn't have types. Undefined constructs
- have no meaning. i = i++ is just as meaningless as #include <memory.h>
- : I have no idea what either of them means. (Note that asm { mov ax,
- bx } on the other hand is a syntax error.) An implementation or
- another standard is allowed to extend the language by providing
- meaning for undefined constructs.
-
- In C++ draft standard there are two words used in such cases:
- "undefined behavior" and "implementation defined behavior" - and I think
- they are used accordingly for 1. and 2. As I understand now in C standard
- there is no such clear division. But it does not mean that the problem
- does not exist and I believe it is very wrong to claim that in every
- case where behavier is not defined by C standard we may loose all
- data from our hard disk!
-
- C does have implementation defined behaviour too. For example, whether
- char is signed or unsigned is implementation defined. The
- implementation documentation has to specify the choices made for the
- implementation defined behaviours. The standard very clearly
- distinguishes between implementation defined and undefined behaviour,
- and only very rarely, as in (int)(char*)0, allows an implementation to
- define something as undefined (This seems to be the majority view
- here: claims have been made that implementation always has the right).
-
- So, for undefined behaviour, you may indeed loose all your data on the
- hard disk.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-